package com.itheima.mapper;

import com.itheima.pojo.Article;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where username = #{username} ")
    User findByUserName(String username);

    @Select("select id from user where username = #{username} ")
    int findIdByUserName(String username);

    @Insert("insert into user (username,password,email,nickname,role,update_time,create_time)" +
            " values(#{username},#{password},#{email},#{nickname},0,now(),now())")
    void add(String username, String password,String email,String nickname);

    @Update("update user set nickname = #{nickname},email = #{email}, update_time = #{updateTime},role = #{role} where id = #{id}")
    void update(User user);

    @Update("update user set user_pic = #{avatarUrl},update_time = now() where id = #{id}")
    void updateAvatar(String avatarUrl,Integer id);

    @Update("update user set password = #{password} where id = #{id}")
    void updatePwd(String password, Integer id);


    @Select("select email from user where username = #{username} ")
    String findEmailByUserName(String username);

    List<User> findAllUser( String nickname, String email);

    @Select("delete from user where id = #{id} ")
    String deleteUser(Integer id);
}
